package com.cx.zhshopping.ui.binding_adapter;

import androidx.databinding.BindingAdapter;

import com.blankj.utilcode.util.Utils;
import com.cx.zhshopping.R;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.widget.MsgView;

import java.util.ArrayList;

public class TabLayoutBindingAdapter {


    @BindingAdapter(value = {"initTablayout"}, requireAll = false)
    public static void initTabLayout(CommonTabLayout tabLayout, ArrayList<CustomTabEntity> mTabEntities) {
        tabLayout.setTabData(mTabEntities);

    }

    @BindingAdapter(value = {"tabSelectedListener"}, requireAll = false)
    public static void tabSelectedListener(CommonTabLayout tabLayout, OnTabSelectListener listener) {
        tabLayout.setOnTabSelectListener(listener);
    }

    @BindingAdapter(value = {"tabPosition"}, requireAll = false)
    public static void selectPosition(CommonTabLayout tabLayout, int position) {
        tabLayout.setCurrentTab(position);
    }

    @BindingAdapter(value = "setTabDotNum", requireAll = false)
    public static void setTabDot(CommonTabLayout tabLayout, int num) {

        if (num > 0) {
            tabLayout.showMsg(3, num);
            MsgView msgView = tabLayout.getMsgView(3);
            msgView.setTextSize(7f);
            msgView.setBackgroundColor(Utils.getApp().getColor(R.color.black));
            tabLayout.setMsgMargin(3, -20, 5);

        } else {
            tabLayout.hideMsg(3);
        }
//        //设置未读消息红点
//        if (num>0){
//            tabLayout.showDot(3);
//            MsgView msgNews = tabLayout.getMsgView(3);
//            if (msgNews != null)
//            {
//                UnreadMsgUtils.setSize(msgNews, SizeUtils.dp2px(7.5f));
//            }
//        }else {
//            tabLayout.hideMsg(3);
//        }

    }


}
